home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / P3MBDEL.AS_ / p3mbdel.asp
Encoding:
Text File  |  2003-02-21  |  8.7 KB  |  296 lines

  1. <%@ Language=VBScript   %>
  2. <%    Option Explicit     %>
  3. <%
  4.     '-------------------------------------------------------------------------
  5.     ' POP3 Mail Add-in - Mailboxes - Delete
  6.     ' Copyright (C) Microsoft Corporation.  All rights reserved.
  7.     '-------------------------------------------------------------------------
  8. %>
  9.     <!-- #include virtual="/admin/inc_framework.asp" -->
  10.     <!-- #include virtual="/admin/ots_main.asp" -->
  11.     <!-- #include file="p3cminc.asp" -->
  12. <%
  13.  
  14.     '-------------------------------------------------------------------------
  15.     ' Global Constants
  16.     '-------------------------------------------------------------------------
  17.     Dim SOURCE_FILE
  18.     SOURCE_FILE = SA_GetScriptFileName()
  19.     
  20.     Const FLD_NAME = "fldName"
  21.     Const FLD_DELETEUSER    = "fldDeleteUser"
  22.  
  23.     '-------------------------------------------------------------------------
  24.     ' Global Variables
  25.     '-------------------------------------------------------------------------
  26.     Dim g_page
  27.     Dim g_rgFailures
  28.     Dim g_nFailures
  29.     
  30.     Dim g_strDomainName
  31.     g_strDomainName = GetDomainName()
  32.     
  33.     
  34.     '----------------------------------------------------------------------
  35.     ' Global Localized Strings
  36.     '----------------------------------------------------------------------
  37.     Dim l_strPageTitle
  38.     If (Request.Form(FLD_NAME).Count > 0) Then
  39.         ' Set the title to the error title, even though we don't know
  40.         ' whether an error occurred.  By the time we know an error occured,
  41.         ' it will be too late to update the title, and if no error occurs,
  42.         ' the user will be redirected back to the OTS.
  43.         l_strPageTitle    = GetLocString(RES_DLL_NAME, _
  44.                                        POP3_PAGETITLE_MAILBOXES_DELETEERROR, _
  45.                                        "")
  46.     Else
  47.         l_strPageTitle    = GetLocString(RES_DLL_NAME, _
  48.                                        POP3_PAGETITLE_MAILBOXES_DELETE, _
  49.                                        "")
  50.     End If
  51.  
  52.     Dim l_strConfirmPrompt
  53.     l_strConfirmPrompt    = GetLocString(RES_DLL_NAME, _
  54.                                        POP3_PROMPT_MAILBOXES_DELETE, _
  55.                                        "")
  56.     Dim l_strErrorPrompt
  57.     l_strErrorPrompt    = GetLocString(RES_DLL_NAME, _
  58.                                        POP3_PROMPT_MAILBOXES_DELETEERROR, _
  59.                                        "")
  60.     Dim l_strRetryPrompt
  61.     l_strRetryPrompt    = GetLocString(RES_DLL_NAME, _
  62.                                        POP3_PROMPT_MAILBOXES_DELETERETRY, _
  63.                                        "")
  64. '                                               POP3_CAPTION_MAILBOXES_DEL_DELETE, _
  65.     Dim l_strCaptionDeleteUser
  66.     l_strCaptionDeleteUser        = GetLocString(RES_DLL_NAME, _
  67.                                                 POP3_CAPTION_MAILBOXES_DELETEUSER, _
  68.                                                 "")
  69.  
  70.  
  71.     '**********************************************************************
  72.     '*                        E N T R Y   P O I N T
  73.     '**********************************************************************
  74.     
  75.     Call SA_CreatePage(l_strPageTitle, "", PT_PROPERTY, g_page)
  76.     Call SA_ShowPage  (g_page)
  77.  
  78.  
  79.     '**********************************************************************
  80.     '*                H E L P E R  S U B R O U T I N E S 
  81.     '**********************************************************************
  82.     '---------------------------------------------------------------------
  83.     ' OutputNameList
  84.     '---------------------------------------------------------------------
  85.     Sub OutputNameList(rgMailboxesTable, nRows)
  86.         '
  87.         ' Sort the names.
  88.         '
  89.         Call SAQuickSort(rgMailboxesTable, 1, nRows, 1, 0)
  90.         
  91.         '
  92.         ' Output the names in a bulleted list.
  93.         '
  94.         Response.Write("<UL>" & vbCrLf)
  95.         
  96.         Dim strAddress
  97.         
  98.         Dim iRow
  99.         For iRow = 1 to nRows
  100.             strAddress = rgMailboxesTable(iRow, 0) & "@" & g_strDomainName
  101. %>
  102.             <LI><%=Server.HTMLEncode(strAddress)%></LI>
  103.             <INPUT TYPE="hidden" NAME="<%=FLD_NAME%>"
  104.                    VALUE="<%=Server.HTMLEncode(rgMailboxesTable(iRow, 0))%>">
  105. <%
  106.         Next
  107. %>
  108.         </UL>
  109. <%
  110.     End Sub
  111.     
  112.     '---------------------------------------------------------------------
  113.     ' ServeCommonJavaScript
  114.     '---------------------------------------------------------------------
  115.     Function ServeCommonJavaScript()
  116.     %>
  117.         <script language="JavaScript" src="../inc_global.js">
  118.         </script>
  119.         <script language="JavaScript">
  120.         
  121.         function Init(){}
  122.         function ValidatePage(){return true;}
  123.         function SetData(){}
  124.     
  125.         </script>
  126.     <%
  127.     End Function
  128.  
  129.  
  130.     '**********************************************************************
  131.     '*                    E V E N T   H A N D L E R S
  132.     '**********************************************************************
  133.     
  134.     '---------------------------------------------------------------------
  135.     ' OnInitPage
  136.     '---------------------------------------------------------------------
  137.     Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  138.         OnInitPage = true
  139.         g_nFailures = 0
  140.         Session("bDeleteUser") = ""
  141.     End Function
  142.     
  143.     '---------------------------------------------------------------------
  144.     ' OnServePropertyPage
  145.     '---------------------------------------------------------------------
  146.     Public Function OnServePropertyPage(ByRef PageIn, ByRef EventArg)
  147.         On Error Resume Next
  148.         
  149.         Session(SESSION_POP3DOMAINNAME) = g_strDomainName
  150.  
  151.         '
  152.         ' Emit Javascript functions required by Web Framework
  153.         Call ServeCommonJavaScript()
  154.  
  155.         If (g_nFailures > 0) Then
  156.             '
  157.             ' Output the error prompt and sorted list of failed templates.
  158.             '        
  159.             Response.Write(l_strErrorPrompt & "<BR>" & vbCrLf)
  160.             Call OutputNameList(g_rgFailures, g_nFailures)
  161.             Response.Write("<BR>" & l_strRetryPrompt & vbCrLf)
  162.             
  163.             OnServePropertyPage = true
  164.  
  165.             If (Err.number <> 0) Then
  166.                 Call SA_SetErrMsg( HandleUnexpectedError() )
  167.             End If
  168.  
  169.             Exit Function
  170.         End If
  171.         
  172.         Dim nRows
  173.         nRows = OTS_GetTableSelectionCount("")
  174.  
  175.         '
  176.         ' Get the list of selected devices.
  177.         '
  178.         Dim rgMailboxesTable
  179.         ReDim rgMailboxesTable(nRows, 0)
  180.         
  181.         Dim strUserName
  182.         Dim iRow
  183.         For iRow = 1 to nRows
  184.             If (OTS_GetTableSelection("", iRow, strUserName)) Then
  185.                 rgMailboxesTable(iRow, 0) = strUserName
  186.             Else
  187.                 Call SA_SetErrMsg( HandleUnexpectedError() )
  188.                 Call SA_TraceErrorOut(SOURCE_FILE, _
  189.                                       "Failed to get OTS selection.")
  190.             End If
  191.         Next
  192.  
  193.         '
  194.         ' Output the confirmation prompt and sorted list of names.
  195.         '        
  196.         Response.Write(l_strConfirmPrompt & "<BR>" & vbCrLf)
  197.         Call OutputNameList(rgMailboxesTable, nRows)
  198.         
  199.         '
  200.         ' If we are not using the MD5 Hash, then lets allow them to delete the user too.
  201.         Dim oConfig
  202.         Set oConfig = Server.CreateObject("P3Admin.P3Config")
  203.         
  204.         If ( oConfig.Authentication.CurrentAuthMethod <> AUTH_FILE ) Then
  205.             %>        
  206.                 <INPUT TYPE="CHECKBOX" NAME="<%=FLD_DELETEUSER%>" ID="<%=FLD_DELETEUSER%>">
  207.                 <LABEL FOR="<%=FLD_DELETEUSER%>"><%=Server.HTMLEncode(l_strCaptionDeleteUser)%></LABEL>
  208.             <%
  209.         End If
  210.  
  211.         If (Err.number <> 0) Then
  212.             Call SA_SetErrMsg( HandleUnexpectedError() )
  213.         End If
  214.             
  215.         OnServePropertyPage = true
  216.     End Function
  217.  
  218.     '---------------------------------------------------------------------
  219.     ' OnPostBackPage
  220.     '---------------------------------------------------------------------
  221.     Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  222.         OnPostBackPage = true
  223.     End Function
  224.  
  225.     '---------------------------------------------------------------------
  226.     ' OnSubmitPage
  227.     '---------------------------------------------------------------------
  228.     Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  229.         On Error Resume Next
  230.         
  231.         OnSubmitPage = false
  232.         
  233.         Dim oConfig
  234.         Set oConfig = Server.CreateObject("P3Admin.P3Config")
  235.  
  236.         Dim nRows
  237.         nRows = Request.Form(FLD_NAME).Count
  238.         
  239.         ' Create an array to hold the names of any templates that could
  240.         ' not be deleted.
  241.         ReDim g_rgFailures(nRows, 0)
  242.         g_nFailures = 0
  243.  
  244.         ' Keep state for the Delete associated user checkbox.
  245.         If ( Session("bDeleteUser") = "" ) Then
  246.             If ( StrComp(Request.Form(FLD_DELETEUSER), "on", vbTextCompare) = 0 ) Then
  247.                 Session("bDeleteUser") = true
  248.             Else
  249.                 Session("bDeleteUser") = false
  250.             End If
  251.         End If
  252.  
  253.         '
  254.         ' Iterate over the selected templates and delete them.
  255.         '
  256.         Dim strUserName        
  257.         Dim iRow
  258.         For iRow = 1 to nRows
  259.             strUserName = Request.Form(FLD_NAME).Item(iRow)
  260.  
  261.             ' Here we actually do the delete.
  262.             If ( CBool(Session("bDeleteUser")) ) Then
  263.                 oConfig.Domains.Item(g_strDomainName).Users.RemoveEx(strUserName)
  264.             Else
  265.                 oConfig.Domains.Item(g_strDomainName).Users.Remove(strUserName)
  266.             End If
  267.             
  268.             If (Err.number <> 0) Then
  269.                 g_nFailures = g_nFailures + 1
  270.                 g_rgFailures(g_nFailures, 0) = strUserName
  271.                     
  272.                 If (Err.number <> 0) Then
  273.                     Call SA_SetErrMsg( HandleUnexpectedError() )
  274.                     
  275.                     Err.Clear()
  276.                     ' Don't return -- keep trying to delete the rest of the objects.
  277.                 End If
  278.             End If
  279.         Next
  280.         
  281.         If (g_nFailures > 0) Then
  282.             OnSubmitPage = false
  283.             Exit Function
  284.         End If
  285.         
  286.         OnSubmitPage = true
  287.     End Function
  288.     
  289.     '---------------------------------------------------------------------
  290.     ' OnClosePage
  291.     '---------------------------------------------------------------------
  292.     Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  293.         OnClosePage = true
  294.     End Function
  295. %>
  296.